package com.building18.configs;



import com.building18.handler.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册 Interceptor 拦截器
        InterceptorRegistration registration = registry.addInterceptor(loginInterceptor);

        registration.addPathPatterns("/**");  // 拦截器所有的请求
        registration.excludePathPatterns(
                // 静态资源
                "/**/*.html",
                "/**/*.js",
                "/**/*.css",
                "/**/*.ico",
                // 登录相关
                "/**/login",
                "/",
                // Swagger 及 Knife4j 路径
                "/swagger-ui.html",
                "/swagger-ui/**", // Swagger 3.0 路径
                "/swagger-resources/**",
                "/v2/api-docs",
                "/v3/api-docs/**", // OpenAPI 3.0 文档
                "/webjars/**",
                "/doc.html", // Knife4j 首页
                "/doc.html/**" // Knife4j 相关资源
//                "/swagger-resources/**",
//                                "/webjars/**", "/v2/**", "/swagger-ui.html/**","/filter/**"
        );
    }
}